﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Objects;
using System.Collections.Generic;
using BAL;

public partial class Admin_UCControls_UCMauThe : System.Web.UI.UserControl
{
    public static string srtPath;

    public static MauThe ItemMauThe = new MauThe();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetMauTheByIdChuDe(0);
            GetAllChuDe();
           
        }
    }

    public string PathImage()
    {
        return srtPath = "images/Generic Card/MauThe";
    }

    //---- Chu De -----

    public static List<ChuDe> ListChuDe = new List<ChuDe>();

    public void GetAllChuDe()
    {
        ListChuDe = BAL.BALChuDe.GetAllItem();

        ChuDe item = new ChuDe();

        item.Id = 0;
        item.TenChuDe = "-- Chọn Chủ đề --";

        ListChuDe.Insert(0, item);

        ddlChuDe.DataTextField = "TenChuDe";
        ddlChuDe.DataValueField = "Id";
        ddlChuDe.DataSource = ListChuDe;
        ddlChuDe.DataBind();
    }

    protected void ddlChuDe_SelectedIndexChanged(object sender, EventArgs e)
    {
        int idChuDe = Convert.ToInt16(ddlChuDe.SelectedValue.ToString());
        string path = "~/images/Generic Card/ChuDe/";

        if (idChuDe > 0)
        {

            foreach (ChuDe itemChuDe in ListChuDe)
            {
                if (idChuDe == itemChuDe.Id)
                {
                    imgChuDe.ImageUrl = path + itemChuDe.DuongDan.ToString();

                }
            }
        }
        else
        {
            imgChuDe.ImageUrl = null;
        }

       GetMauTheByIdChuDe(idChuDe);
    }

    //---- Mau the  -----

    public static List<MauThe> ListMauThe;

    public void GetMauTheByIdChuDe(int idChuDe)
    {

        ListMauThe = new List<MauThe>();
     
        ListMauThe = BALMauThe.GetByIdChuDe(idChuDe);
        dtlMauThe.DataSource = ListMauThe;
        dtlMauThe.DataBind();

    }

    protected void btnThem_Click(object sender, EventArgs e)
    {
        Response.Redirect("../Admin/MauThe_Update.aspx");
    }


    protected void dtlMauThe_ItemCommand(object source, DataListCommandEventArgs e)
    {
        int item;

        if (e.CommandName == "Xoa")
        {
            foreach (MauThe itemMauThe in ListMauThe)
            {
                if (itemMauThe.Id == Convert.ToInt16(e.CommandArgument.ToString()))
                {
                    item = BALMauThe.Update_MauThe(Convert.ToInt16(e.CommandArgument.ToString()), itemMauThe.IdChuDe, itemMauThe.TenMauThe.ToString(), itemMauThe.DuongDan.ToString(), itemMauThe.GhiChu.ToString(), -1, itemMauThe.SapXep);

                }
            }
           
        }
    }
}
